﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:ADU_CONSCHEME
	/// </summary>
	public partial class ADU_CONSCHEME : BaseDAL<GSLMS.Entity.TB_ADU_CONSCHEME>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public ADU_CONSCHEME()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_ADU_CONSCHEME model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_ARRID", model.ARRID),
								new OracleParameter("P_PROGNO", model.PROGNO),
								new OracleParameter("P_PROGCAT", model.PROGCAT),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_RATE", model.RATE),
								new OracleParameter("P_MANAGERATE", model.MANAGERATE),
								new OracleParameter("P_GENERALRATE", model.GENERALRATE),
								new OracleParameter("P_LOANTIME", model.LOANTIME),
								new OracleParameter("P_LOANPHASE", model.LOANPHASE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_ADVAMT", model.ADVAMT),
								new OracleParameter("P_AUDITREMARK", model.AUDITREMARK)};
  
			for (int i = 0; i < 14; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_adu_conscheme_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_ADU_CONSCHEME model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_ARRID", model.ARRID),
								new OracleParameter("P_PROGNO", model.PROGNO),
								new OracleParameter("P_PROGCAT", model.PROGCAT),
								new OracleParameter("P_AMT", model.AMT),
								new OracleParameter("P_RATE", model.RATE),
								new OracleParameter("P_MANAGERATE", model.MANAGERATE),
								new OracleParameter("P_GENERALRATE", model.GENERALRATE),
								new OracleParameter("P_LOANTIME", model.LOANTIME),
								new OracleParameter("P_LOANPHASE", model.LOANPHASE),
								new OracleParameter("P_LOANPHASETYPE", model.LOANPHASETYPE),
								new OracleParameter("P_ADVAMT", model.ADVAMT),
								new OracleParameter("P_AUDITREMARK", model.AUDITREMARK)};
  
			for (int i = 0; i < 14; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_adu_conscheme_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_adu_conscheme_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_ADU_CONSCHEME DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_ADU_CONSCHEME model = new GSLMS.Entity.TB_ADU_CONSCHEME();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["ARRID"]!=null && dr["ARRID"].ToString()!="")
				{
					model.ARRID=OracleHelper.ToLong(dr["ARRID"].ToString());
				}
				if(dr["PROGNO"]!=null && dr["PROGNO"].ToString()!="")
				{
                    model.PROGNO = OracleHelper.ToInt(dr["PROGNO"].ToString());
				}
				if(dr["PROGCAT"]!=null && dr["PROGCAT"].ToString()!="")
				{
					model.PROGCAT=dr["PROGCAT"].ToString();
				}
				if(dr["AMT"]!=null && dr["AMT"].ToString()!="")
				{
					model.AMT=OracleHelper.ToDecimal(dr["AMT"].ToString());
				}
				if(dr["RATE"]!=null && dr["RATE"].ToString()!="")
				{
					model.RATE=OracleHelper.ToDecimal(dr["RATE"].ToString());
				}
				if(dr["MANAGERATE"]!=null && dr["MANAGERATE"].ToString()!="")
				{
					model.MANAGERATE=OracleHelper.ToDecimal(dr["MANAGERATE"].ToString());
				}
				if(dr["GENERALRATE"]!=null && dr["GENERALRATE"].ToString()!="")
				{
					model.GENERALRATE=OracleHelper.ToDecimal(dr["GENERALRATE"].ToString());
				}
				if(dr["LOANTIME"]!=null && dr["LOANTIME"].ToString()!="")
				{
                    model.LOANTIME = OracleHelper.ToInt(dr["LOANTIME"].ToString());
				}
				if(dr["LOANPHASE"]!=null && dr["LOANPHASE"].ToString()!="")
				{
                    model.LOANPHASE = OracleHelper.ToInt(dr["LOANPHASE"].ToString());
				}
				if(dr["LOANPHASETYPE"]!=null && dr["LOANPHASETYPE"].ToString()!="")
				{
                    model.LOANPHASETYPE = OracleHelper.ToInt(dr["LOANPHASETYPE"].ToString());
				}
				if(dr["ADVAMT"]!=null && dr["ADVAMT"].ToString()!="")
				{
					model.ADVAMT=OracleHelper.ToDecimal(dr["ADVAMT"].ToString());
				}
				if(dr["AUDITREMARK"]!=null && dr["AUDITREMARK"].ToString()!="")
				{
					model.AUDITREMARK=dr["AUDITREMARK"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_ADU_CONSCHEME GetByID(long ID)
		{
			GSLMS.Entity.TB_ADU_CONSCHEME sModel = new GSLMS.Entity.TB_ADU_CONSCHEME();
			string sql = "";
			sql = "select * from TB_ADU_CONSCHEME where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_ADU_CONSCHEME> GetList(GSLMS.Entity.TB_ADU_CONSCHEME searchParam)
		{
			var list=new List<GSLMS.Entity.TB_ADU_CONSCHEME>();
			DataTable dt = null;
			string tblName = "TB_ADU_CONSCHEME";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_ADU_CONSCHEME model = new GSLMS.Entity.TB_ADU_CONSCHEME();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

